package com.svms.web.factory;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author om39a
 * 
 *         This class is used to load the Spring XML i.e the application context
 *         for the first time
 * 
 */
public class ComponentFactory {

	private static ComponentFactory componentFactory;

	private ApplicationContext applicationContext;

	private ComponentFactory() {
		try {
			applicationContext = new ClassPathXmlApplicationContext(
					"svms-web-context.xml");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static ComponentFactory getInstance() {
		if (componentFactory == null) {
			synchronized (ComponentFactory.class) {
				if (componentFactory == null) {
					componentFactory = new ComponentFactory();
				}
			}

		}
		return componentFactory;
	}

	public Object getBean(String beanName) {
		return applicationContext.getBean(beanName);
	}

}
